const Stream = require('stream');

async function readBody(stream){
  //koa中要求所有的异步方法必须包装成promise
  if(stream instanceof Stream){
    return new Promise((resolve, reject) => {
      let res = '';
      stream.on('data', data => {
        res += data;
      });
      stream.on('end', () => {
        resolve(res); // 将内容解析完成 抛出去
      });
    })
  }else {
    return stream;
  }
}

exports.readBody = readBody;
